import java.util.Random;
import java.io.*;

public class PadGenerator {
	private static final int row = 50;
	private static final int column = 80;
	private static final String padDirectory = System.getProperty("user.dir") + "/padFilesGenerated/";
	private String[] padFiles;
	
	public PadGenerator(String padFileList) {
		padFiles = padFileList.split(",");
	}

	public void generatePads() {
		try {
			checkDirectory(padDirectory);
			for (String padFile : padFiles) {
				byte[] p = new byte[row * column];
				for (int i = 0; i < row; i++) {
					for (int j = 0; j < column-1; j++) {
						p[(i*column)+j] = (byte)(new Random().nextInt(95) + 32);
					}
					p[(i*column)+(column-1)] = ' ';
				}
				writeFile(padDirectory + padFile , p);
			}
		}
		catch (Exception e) {
			System.err.println("ERROR: " + e);
		}
	}
	
	private void checkDirectory(String directory) {
		File d = new File(directory);
		if (!d.exists()) { d.mkdir(); }
		String[] f = d.list();
		for (int i = 0; i < f.length; i++) { new File(d, f[i]).delete(); }
	}

	private void writeFile(String fileName, byte[] b) throws Exception {
			FileOutputStream fos = new FileOutputStream(fileName);
			fos.write(b);
			fos.close();
	}
}
